//
//  HomePageViewController.m
//  LoanMoney
//
//  Created by gynjobs on 2017/8/28.
//  Copyright © 2017年 cangming. All rights reserved.
//

#import "HomePageViewController.h"
#import "CustomTabbarItem.h"
#import "ButtonView.h"
#import "LoanPageViewController.h"
#import "AboutUSViewController.h"
#define grayTextColor @"#f6f6f6"
#define BlackTextColor @"#474747"
#define BlueTextColor  @"#318DFF"
#define sectionColor @"#f6f6f6"
#define DisableColor @"#e8e8e8"
#define IconMarginLeft 20.0
#define BannerHeight 280.0
#define ButtonHeight 110.0
#define ButtonMargin 15.0
#define BoomViewHeight 30.0
@interface HomePageViewController ()<ButtonViewDelegate>
@property(strong,nonatomic)UIScrollView *backScrollerView;
@property(strong,nonatomic)UIView *ContentView;
@property(strong,nonatomic)UIView *BannerView;
@property(strong,nonatomic)UIView *IconView;
@property(strong,nonatomic)UIView *buttonView;
@property(strong,nonatomic)UIView *BoomView;
@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"首页";
    self.view.backgroundColor = [UIColor colorWithString:sectionColor];
    //添加滚动视图
    [self addBackScrollerViewForView];
    [self addRightAboutUs];
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    BaseCommondTabbarController *tabb = (BaseCommondTabbarController *)self.tabBarController;
    [tabb HiddenTheTabbar:NO];
}
#pragma mark ---添加右侧的按钮---
- (void)addRightAboutUs{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0, 0, 65, 20);
    rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightButton setTitle:@"关于我们" forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
}
-(void)rightAction{
    AboutUSViewController *aboutUS = [[AboutUSViewController alloc]init];
    [self.navigationController pushViewController:aboutUS animated:YES];
    BaseCommondTabbarController *tabb = (BaseCommondTabbarController *)self.tabBarController;
    [tabb HiddenTheTabbar:YES];
}
#pragma mark ---添加子视图---
- (void)addBackScrollerViewForView{
    
    self.backScrollerView = [[UIScrollView alloc]init];
    self.backScrollerView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.backScrollerView];
    [self.backScrollerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.top.equalTo(self.view);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    self.ContentView = [[UIView alloc]init];
    [self.backScrollerView  addSubview:self.ContentView];
    self.ContentView.backgroundColor = [UIColor clearColor];
    [self.ContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backScrollerView.mas_left);
        make.width.mas_equalTo(WINSIZEWIDTH);
        make.top.equalTo(self.backScrollerView.mas_top);
        make.bottom.equalTo(self.backScrollerView);
    }];
    //添加子视图
    [self addBannerViewForScrollerView];
    [self addIconViewForScrollerView];
    [self addButtonViewForScrollerView];
    [self addBoomViewForScrollerView];
}
- (void)addBannerViewForScrollerView{
    self.BannerView = [[UIView alloc]init];
    self.BannerView.backgroundColor = [UIColor clearColor];
    [self.ContentView addSubview:self.BannerView];
    [self.BannerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.ContentView.mas_top);
        make.left.equalTo(self.ContentView.mas_left);
        make.right.equalTo(self.ContentView.mas_right);
        make.height.mas_equalTo(R_Y_H(BannerHeight));
    }];
    UIImageView *testimage = [[UIImageView alloc]init];
    testimage.backgroundColor = [UIColor clearColor];
    testimage.image = [UIImage imageNamed:@"bannerModule15.png"];
    [self.BannerView addSubview:testimage];
    [testimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.BannerView);
    }];

}
- (void)addIconViewForScrollerView{
    self.IconView = [[UIView alloc]init];
    self.IconView.backgroundColor = [UIColor colorWithString:sectionColor];
    [self.ContentView addSubview:self.IconView];
    
    UIImageView *testimage = [[UIImageView alloc]init];
    testimage.backgroundColor = [UIColor clearColor];
    testimage.image = [UIImage imageNamed:@"amount_limit.png"];
    [self.IconView addSubview:testimage];
    [testimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.IconView);
        make.left.equalTo(self.IconView.mas_left).offset(R_Y_W(IconMarginLeft));
        make.height.equalTo(testimage.mas_width);
        make.top.equalTo(self.IconView.mas_top).offset(R_Y_W(IconMarginLeft));
    }];
    
    [self.IconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.BannerView.mas_bottom);
        make.left.equalTo(self.BannerView.mas_left);
        make.right.equalTo(self.BannerView.mas_right);
    }];
}
- (void)addButtonViewForScrollerView{
    self.buttonView = [[UIView alloc]init];
    self.buttonView.backgroundColor = [UIColor colorWithString:sectionColor];
    [self.ContentView addSubview:self.buttonView];

    ButtonView *buttonView = [[ButtonView alloc]init];
    buttonView.delegate = self;
    buttonView.backgroundColor = [UIColor colorWithString:sectionColor];
    buttonView.frame = CGRectMake(0, 0, WINSIZEWIDTH, R_Y_H(120*1.35));
    buttonView.buttonTitle = @"立即申请";
    buttonView.buttonTitleDisableColor = DisableColor;
    buttonView.buttonTitleEnableColor = @"#ffffff";
    buttonView.ButtonEnableColor = NavBarColorStirng;
    buttonView.buttonDisableColor = @"#ffffff";
    buttonView.marginLeft = R_Y_W(20*1.35);
    buttonView.marginTop = R_Y_H(20*1.35);
    buttonView.isEnable = YES;
    [self.buttonView addSubview:buttonView];
    UILabel *detailLabel = [[UILabel alloc]init];
    detailLabel.backgroundColor = [UIColor clearColor];
    detailLabel.textColor = [UIColor colorWithString:NavBarColorStirng];
    detailLabel.textAlignment = NSTextAlignmentCenter;
    detailLabel.numberOfLines = 0;
    detailLabel.font = [UIFont systemFontOfSize:12];
    detailLabel.text = @"注：借款金额和限期以实际放款金额为准";
    [self.buttonView addSubview:detailLabel];
    [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(buttonView.mas_bottom).offset(0);
        make.left.equalTo(buttonView.mas_left);
        make.right.equalTo(buttonView.mas_right);
        make.bottom.equalTo(self.buttonView.mas_bottom).offset(-5);
    }];
    [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.IconView.mas_left);
        make.right.equalTo(self.IconView.mas_right);
        make.top.equalTo(self.IconView.mas_bottom);
    }];
}
- (void)addBoomViewForScrollerView{
    self.BoomView = [[UIView alloc]init];
    self.BoomView.backgroundColor = [UIColor colorWithString:sectionColor];
    [self.ContentView addSubview:self.BoomView];
    [self.BoomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buttonView.mas_bottom);
        make.left.equalTo(self.buttonView.mas_left);
        make.right.equalTo(self.buttonView.mas_right);
        make.bottom.equalTo(self.ContentView.mas_bottom);
    }];
    
        UILabel *detailLabel = [[UILabel alloc]init];
        detailLabel.backgroundColor = [UIColor colorWithString:sectionColor];
        detailLabel.textColor = [UIColor grayColor];
        detailLabel.textAlignment = NSTextAlignmentCenter;
        detailLabel.numberOfLines = 0;
        detailLabel.font = [UIFont systemFontOfSize:12];
        detailLabel.text = @"由厦门厚泽金融服务有限公司提供高品质服务";
        [self.BoomView addSubview:detailLabel];
        [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.BoomView .mas_top).offset(10);
            make.left.equalTo(self.BoomView.mas_left);
            make.right.equalTo(self.BoomView.mas_right);
            make.bottom.equalTo(self.BoomView.mas_bottom).offset(-10);
        }];
}
#pragma mark ---DelegateFuction---
-(void)clickButtonWith:(ButtonView *)buttonView{
    LoanPageViewController *homeC = [[LoanPageViewController alloc]init];
    [self.navigationController pushViewController:homeC animated:YES];
    BaseCommondTabbarController *tabb = (BaseCommondTabbarController *)self.tabBarController;
    [tabb HiddenTheTabbar:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
